@include('usercenter.header')
    <div class="template-page-wrapper">
      <div class="navbar-collapse collapse templatemo-sidebar">
        <ul class="templatemo-sidebar-menu">
          <li>
            <form class="navbar-form">
              <input type="text" class="form-control" id="templatemo_search_box" placeholder="搜索...">
              <span class="btn btn-default"><i class="fa fa-search"></i></span>
            </form>
          </li>
          <li><a href="{{url('user/usercente')}}"><i class="fa fa-home"></i>用户中心</a></li>
          <li class="sub active">
            <a href="javascript:;">
              <i class="fa fa-database"></i> 账户设置 <div class="pull-right"><span class="caret"></span></div>
            </a>
            <ul class="templatemo-submenu">
              <li><a href="#">修改昵称</a></li>
              <li><a href="#">修改密码</a></li>
              <li><a href="#">修改绑定手机</a></li>
              <li><a href="#">修改绑定邮箱</a></li>
              <li><a href="#">修改密保</a></li>
            </ul>
          </li>
          <li class="sub">
            <a href="javascript:;">
              <i class="fa fa-database"></i> 比赛详情
            </a>
          </li>
          <li class="sub">
            <a href="javascript:;">
              <i class="fa fa-database"></i> 财富中心 <div class="pull-right"><span class="caret"></span></div>
            </a>
            <ul class="templatemo-submenu">
              <li><a href="#">我的煤球</a></li>
              <li><a href="#">充值记录</a></li>
              <li><a href="#">充值中心</a></li>
            </ul>
          </li>
          <li class="sub">
            <a href="javascript:;">
              <i class="fa fa-database"></i> 收信箱 <div class="pull-right"><span class="caret"></span></div>
            </a>
            <ul class="templatemo-submenu">
              <li><a href="#">所有信件</a></li>
              <li><a href="#">未读信件</a></li>
              <li><a href="#">已读信件</a></li>
            </ul>
          </li>
          <li><a href="javascript:;" data-toggle="modal" data-target="#confirmModal"><i class="fa fa-sign-out"></i>返回首页</a></li>
        </ul>
      </div><!--/.navbar-collapse -->

      <div class="templatemo-content-wrapper">
        <div class="templatemo-content">
          <ol class="breadcrumb row">
            <li><a href="index.html">用户中心</a></li>
            <li><a href="#">账户设置</a></li>
            <li class="active">修改昵称</li>
          </ol>

        

<!-- startmyself -->

             <div class="row">
               <div class="panel panel-info">
                 <div class="panel-heading">修改昵称</div>
               </div>
             </div>
            

             <form id="edit" action="#" method="post" class="form-group">
              {!! csrf_field() !!}
              <table class="table">
                <tr>
                  <td>
                     <div class="input-group input-group-lg col-md-5">
                     <span class="bg-info input-group-addon" id="basic-addon1">您现在的昵称为<font color="red">{{ Session::get('user_nick')}}</font></span>
                    </div> 
                  </td>
                </tr>

                <tr>
                  <td>
                    <div class="input-group input-group-lg col-md-5">
                      <span class="bg-info input-group-addon" id="basic-addon1">新的昵称</span>
                      <input id="newnick" name="user_nick" type="text" class="form-control" placeholder="昵称必须是3到10位的字母或中文" aria-describedby="basic-addon1">
                    </div>                     
                   <div id="nkdiv" class="alert-warning col-sm-2"></div>               
                  </td>
                </tr>
            
                <tr>
                  <td>
                   <input type="submit" class="btn-info btn-primary btn-lg" value="提交修改">
                 </td>
                </tr>
              </table>             
             </form>
         
<!-- /startmyself -->

        </div>
      </div>
      <!-- Modal -->
     
    @include('usercenter.footer')
    </div>

    <script src="/user/usercenter/js/jquery.min.js"></script>
    <script src="/user/usercenter/js/bootstrap.min.js"></script>
    <script src="/user/usercenter/js/Chart.min.js"></script>
    <script src="/user/usercenter/js/templatemo_script.js"></script>
    <script type="text/javascript">
        //验证输入的昵称
        $('#newnick').blur(function(){
           if(!($('#newnick').val() == '')){
              //验证输入的昵称是否存在
              var data = {
                'type' : 'user_nick',
                'input': $('#newnick').val()
              };
            $.ajax({
              url:'/checktype',
              type: 'POST',
              data: data,
              async:true,
              success:function(ev){
                console.log(ev);
                if(ev == 1) {
                   $('#tishi').remove();
                   $('#nkdiv').empty();//移除原有的提示
                   $('#nkdiv').append('<span id="tishi">该用户名已存在</span>');
                   return false;
                }else{
                  $('#tishi').remove();
                  $('#nkdiv').empty();
                  $('#nkdiv').append('<span id="nulltishi">用户名可用</span>'); 
                }
              },
              error:function(ev){
                  
              }      
            
            });
          }
        });

        //提交修改昵称
        $('#edit').submit(function(){
          var nicdata = {'input': $('#newnick').val()};
          $.ajax({
            url:'/user/editnick',
            type: 'POST',
            data: nicdata,
            async: true,
            success:function(result){
              if(result){
                alert('你的昵称已修改成功');
              }else{
                alert('信号不稳定,先玩会游戏再修改吧');
              }
      
            },
            error:function(result){

            }
          });
  
        });

    </script>
</body>
</html>
